﻿<cfscript>
/** 
* Senate Frameworks turnProperty
* 
* @hint "The course choosing-turn property object handler." 
*/ 

component 
	displayname="public.service.handler.turnProperty" 
	output=false 
	accessors=true 
	{

	/* PROPERTIES */
	property type="boolean" name="Running" default="false" hint="该轮次是否可用";
	
	property type="boolean" name="ProgramTask" default="false" hint="是否开放计划课程选课";
	property type="boolean" name="CommonTask" default="false" hint="是否开放全校通选课选课";
	property type="boolean" name="Retaking" default="false" hint="是否开放重修选课";

	property type="boolean" name="Assist" default="false" hint="是否开放辅修选课";
	property type="boolean" name="Secondary" default="false" hint="是否开放双学位选课";

	property type="boolean" name="FixUp" default="false" hint="是否开放低年级补修选课";
	property type="boolean" name="EarlyGraduate" default="false" hint="是否开放提前毕业选课";

	property type="boolean" name="Sport" default="false" hint="是否开放体育项目课";

	/**
	* @hint "初始化对象"
	* 
	* @Running "该轮次是否可用"
	* @ProgramTask "是否开放计划课程选课"
	* @CommonTask "是否开放全校通选课选课"
	* @Retaking "是否开放重修选课"
	* @Assist "是否开放辅修选课"
	* @Secondary "是否开放双学位选课"
	* @FixUp "是否开放低年级补修选课"
	* @EarlyGraduate "是否开放提前毕业选课"
	* @Sport "是否开放体育项目课"
	*/
	public public.service.handler.turnProperty function init( boolean Running=false, 
																boolean ProgramTask=false, boolean CommonTask=false, boolean Retaking=false,
																boolean Assist=false, boolean Secondary=false,
																boolean FixUp=false, boolean EarlyGraduate = false, 
																boolean Sport=false
																 ) output=false {

		setRunning( arguments.Running );
		
		setProgramTask( arguments.ProgramTask );
		setCommonTask( arguments.CommonTask );
		setRetaking( arguments.Retaking );
		
		setAssist( arguments.Assist );
		setSecondary( arguments.Secondary );

		setFixUp( arguments.FixUp );
		setEarlyGraduate( arguments.EarlyGraduate );
		
		setSport( arguments.Sport );
		
		return this;
	}
	
	/**
	* @hint "将上述属性转换为属性字符串"
	*/
	public string function stringProperty() output=false {
		
		var prop = "";
		
		/* 总体参数变化控制 如果轮次不开放 则所有的子用途都应当设置为 0 */
		if (not getRunning()) {
			
			setProgramTask(false);
			setCommonTask(false);
			setRetaking(false);
			
			setAssist(false);
			setSecondary(false);

			setFixUp(false);
			setEarlyGraduate(false);
			
			setSport(false);
			
		}
		
		
		/* 执行序列化 */
		if (getRunning()) { prop = prop & "1"; } else { prop = prop & "0"; }
	
		if (getProgramTask()) { prop = prop & "1"; } else { prop = prop & "0"; }
		if (getCommonTask()) { prop = prop & "1"; } else { prop = prop & "0"; }
		if (getRetaking()) { prop = prop & "1"; } else { prop = prop & "0"; }

		if (getAssist()) { prop = prop & "1"; } else { prop = prop & "0"; }
		if (getSecondary()) { prop = prop & "1"; } else { prop = prop & "0"; }
		
		if (getFixUp()) { prop = prop & "1"; } else { prop = prop & "0"; }
		if (getEarlyGraduate()) { prop = prop & "1"; } else { prop = prop & "0"; }

		if (getSport()) { prop = prop & "1"; } else { prop = prop & "0"; }

		return left(prop & "000000000000000000000000000000", 30);
		
	}
	
	/**
	* @hint "将属性字符串转换为对象属性"
	* 
	* @fString "属性字符串"
	*/
	public void function parseProperty( required string fString ) output=false {
		
		var i = 0;
		
		for (i=1; i <= len(arguments.fString); i++) {
			
			switch (i) {
				
				case 1:
					/* 第1位 该轮次是否可用 */
					if (yesNoFormat(mid(arguments.fString, i, 1))) { setRunning(true); } else { setRunning(false); }
					break;

				case 2:
					/* 第2位 是否开放计划课程选课 */
					if (yesNoFormat(mid(arguments.fString, i, 1))) { setProgramTask(true); } else { setProgramTask(false); }
					break;
				
				case 3:
					/* 第3位 是否开放全校通选课选课 */
					if (yesNoFormat(mid(arguments.fString, i, 1))) { setCommonTask(true); } else { setCommonTask(false); }
					break;

				case 4:
					/* 第4位 是否开放重修选课 */
					if (yesNoFormat(mid(arguments.fString, i, 1))) { setRetaking(true); } else { setRetaking(false); }
					break;
				
				case 5:
					/* 第5位 是否开放辅修选课 */
					if (yesNoFormat(mid(arguments.fString, i, 1))) { setAssist(true); } else { setAssist(false); }
					break;
				
				case 6:
					/* 第6位 是否开放双学位选课 */
					if (yesNoFormat(mid(arguments.fString, i, 1))) { setSecondary(true); } else { setSecondary(false); }
					break;

				case 7:
					/* 第7位 是否开放低年级补修选课 */
					if (yesNoFormat(mid(arguments.fString, i, 1))) { setFixUp(true); } else { setFixUp(false); }
					break;
				
				case 8:
					/* 第8位 是否开放高年级选课 */
					if (yesNoFormat(mid(arguments.fString, i, 1))) { setEarlyGraduate(true); } else { setEarlyGraduate(false); }
					break;
				
				case 9:
					/* 第9位 是否开放体育项目课 */
					if (yesNoFormat(mid(arguments.fString, i, 1))) { setSport(true); } else { setSport(false); }
					break;
			}
		}
	}



}

</cfscript>